package com.rules.admin.controller.decision;


import com.rules.admin.entity.TreeDedution;
import com.rules.admin.service.TreeDedutionService;
import com.rules.admin.utils.ResultUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Controller
@RequestMapping({"/decisionTreeDedutions"})
public class DecisionTreeDedutionController {
   @Autowired
   private TreeDedutionService treeDedutionService;

   @RequestMapping(
      method = {RequestMethod.POST}
   )
   @ResponseBody
   public Map<String, Object> save(@RequestBody TreeDedution treeDedution) {
      this.treeDedutionService.create(treeDedution);
      return ResultUtils.getSuccessResultData(treeDedution);
   }

   @RequestMapping(
      value = {"/{id}"},
      method = {RequestMethod.PUT}
   )
   @ResponseBody
   public Map<String, Object> updateTreeNode(@RequestBody TreeDedution treeDedution) {
      this.treeDedutionService.updateById(treeDedution);
      return ResultUtils.getSuccessResultData(treeDedution);
   }

   @RequestMapping(
      value = {"/{id}"},
      method = {RequestMethod.DELETE}
   )
   @ResponseBody
   public Map<String, Object> deleteTreeDedution(@PathVariable Long id) {
      this.treeDedutionService.removeById(id);
      return ResultUtils.getSuccessResultData();
   }

   @RequestMapping(
      value = {"/{id}"},
      method = {RequestMethod.GET}
   )
   @ResponseBody
   public Map<String, Object> getTreeDedution(@PathVariable long id) {
      TreeDedution treeDedution = (TreeDedution)this.treeDedutionService.getById(id);
      return ResultUtils.getSuccessResultData(treeDedution);
   }
}
